package com.android.lgc.android_mvp.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * @author $
 * @fileName BaseFragment
 * @date2021/3/9 10:27
 * @describe TODO
 * @desc
 */
public abstract class BaseFragment<V extends BaseView,P extends BasePresenter<V>> extends Fragment {

    private P persenter;
    private V view;

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if(persenter ==null ){
            persenter=createPersenter();
        }
        if(view==null){
            view=createView();
        }

        if(persenter!=null && view!=null){
            persenter.attachView(view);
        }
    }

    public abstract P createPersenter();
    public abstract V createView();

    public  P getPersenter(){
        return persenter;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if(persenter!=null&& view!=null){
            persenter.detachView();
        }
    }
}
